package com.yjd.pub.repayment.service;

import com.alibaba.fastjson.JSON;
import com.yjd.comm.base.dao.IBaseDao;
import com.yjd.comm.base.enums.DbWREnums;
import com.yjd.comm.base.model.PagerModel;
import com.yjd.comm.base.service.impl.BaseServiceImpl;
import com.yjd.comm.credit.model.CreditLineDataModel;
import com.yjd.comm.credit.service.ICreditLineDataService;
import com.yjd.comm.enums.*;
import com.yjd.comm.funds.service.IFundsService;
import com.yjd.comm.fundservice.dto.QKRepaymentCallBackDto;
import com.yjd.comm.fundservice.dto.QkRepaymentAskResponse;
import com.yjd.comm.fundservice.enums.BusTypeEnum;
import com.yjd.comm.fundservice.enums.FundChannelEnum;
import com.yjd.comm.fundservice.model.FundLoanApplyModel;
import com.yjd.comm.fundservice.service.IFundLoanApplyService;
import com.yjd.comm.fundservice.util.QianKangServer;
import com.yjd.comm.msg.MnsMsgInfo;
import com.yjd.comm.order.model.OrderModel;
import com.yjd.comm.order.service.IOrderService;
import com.yjd.comm.org.model.OrganizationModel;
import com.yjd.comm.org.service.IOrganizationService;
import com.yjd.comm.repayment.dto.OverdueDto;
import com.yjd.comm.repayment.dto.RepaymentOrderInfoDto;
import com.yjd.comm.repayment.enums.RepaymentStatusEnum;
import com.yjd.comm.repayment.model.RepaymentClearModel;
import com.yjd.comm.repayment.model.RepaymentDataModel;
import com.yjd.comm.repayment.service.IRepaymentClearService;
import com.yjd.comm.repayment.service.IRepaymentDataService;
import com.yjd.comm.system.model.SysParamModel;
import com.yjd.comm.system.util.SysParamUtil;
import com.yjd.comm.user.model.UserDataModel;
import com.yjd.comm.user.service.IUserDataService;
import com.yjd.comm.util.*;
import com.yjd.comm.vo.Constant;
import com.yjd.msg.comm.annotation.MnsDispose;
import com.yjd.msg.comm.annotation.MnsMsg;
import com.yjd.msg.comm.enums.MsgOrderServiceEnum;
import com.yjd.msg.comm.enums.MsgTypeEnum;
import com.yjd.msg.comm.util.MnsUtils;
import com.yjd.pub.repayment.dao.IRepaymentDataDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * <b>description</b>：用户还款报表业务实现<br>
 * <b>time</b>：2017-06-27 08:56:34 <br>
 * <b>author</b>：  yangchangyan@yijiedai.com
 */
@Service("repaymentDataService")
public class RepaymentDataServiceImpl extends BaseServiceImpl implements IRepaymentDataService {

    @Resource
    IOrderService orderService;

    @Resource
    private IUserDataService userDataService;

    @Resource
    private ICreditLineDataService creditLineDataService;

    /**
     * 插入
     *
     * @param model
     * @return
     * @throws Exception
     */
    public RepaymentDataModel insert(RepaymentDataModel model) throws Exception {
        return this.repaymentDataDao.insertModel(model, true);
    }

    @Override
    public void insertBatch(List models) throws Exception {
        this.repaymentDataDao.insertBatch(models, true);
    }

    /**
     * 更新
     *
     * @param model
     * @return
     * @throws Exception
     */
    public int update(RepaymentDataModel model) throws Exception {
        return this.repaymentDataDao.updateModel(model, true);
    }

    @Override
    public int updateByMap(Map paramMap) throws Exception {
        return this.repaymentDataDao.updateByMap(paramMap, true);
    }

    /**
     * 根据id删除
     *
     * @param id
     * @return
     * @throws Exception
     */
    public int delete(long id) throws Exception {
        Map<Object, Object> paramMap = new HashMap<Object, Object>();
        paramMap.put("id", id);
        return this.repaymentDataDao.deleteModel(paramMap, true);
    }

    /**
     * 还款
     *
     * @param repayment_id 还款报表id
     * @return void
     * @throws
     */
    @Override
    public int repayment(Long repayment_id) throws Exception {

        // 还款开关控制 0 关闭还款功能 1 打开还款功能，在没有配置时默认为关闭状态
        SysParamModel sysParam = SysParamUtil.getSysParamModel(Constant.SysParamKeyEnum.REPAYMENT_SWITCH);
        String repayment_switch = null == sysParam ? "0" : sysParam.getParam_value();
        if ("0".equals(repayment_switch)) {
            FrameUtil.throwBaseException1("还款业务正在维护中，暂时不可用。");
        }

        /**
         * 还款过程：
         * 1、重新计算罚息金额、其他金额也从数据库重新读取（防止修改数据）
         * 2、扣款
         * 3、更新还款报表(实还金额、罚息金额、是否已还)/订单
         */

        RepaymentDataModel currRepay = repaymentDataDao.getModelById(repayment_id, true);
        if (null == currRepay) {
            FrameUtil.throwBaseException1("还款报表不存在");
        }

        if (RepaymentStatusEnum.YES.getCode() == currRepay.getRepayment_status()) {
            FrameUtil.throwBaseException1("该还款报表已还");
        }

        int currLimit = currRepay.getPeriod().intValue();
        if (currLimit > 1) {
            //判断上一期是否已经还款
            RepaymentDataModel preRepay = repaymentDataDao.getModelOne(FrameUtil.newHashMap("order_id", currRepay.getOrder_id(), "period", currRepay.getPeriod() - 1), true);
            if (null == preRepay) {
                FrameUtil.throwBaseException1("还款报表异常");
            }

            if (RepaymentStatusEnum.NO.getCode() == preRepay.getRepayment_status()) {
                FrameUtil.throwBaseException1("请先还上一期！");
            }
        }

        OrderModel orderModel = orderService.getModelById(currRepay.getOrder_id(), DbWREnums.READ);
        if (orderModel == null) {
            FrameUtil.throwBaseException1("当前还款的订单不存在");
        }

        if (StagesStatusEnum.REPAYMENTING.getCode() != orderModel.getStatus().intValue()) {
            FrameUtil.throwBaseException1("当前订单状态不合法！");
        }

        if (orderModel.getLimit_pay().intValue() != currRepay.getPeriod().intValue() - 1) {
            FrameUtil.throwBaseException1("当前还款报表异常！");
        }

        Long currTime = FrameUtil.getTime(null);
        Double repayment_price = currRepay.getRepayment_amount();
        //计算是否有罚息
        OverdueDto overdueDto = RepaymentUtils.overdueInterest(repayment_price, currRepay.getEstimation_repayment_time(), currTime);
        //产生罚息
        Double overdue_price = overdueDto.getOverduePrice();

        //当期利息
        Double interest = ArithUtil.div(orderModel.getInterest_price(), orderModel.getPeriod());
        //扣除账户资金，并记录相应流水
        fundsService.repaymentPay(orderModel.getUser_id(), repayment_price, overdue_price, currRepay.getDiscount_amount(), interest,
                currRepay.getId().toString(), currTime);

        // 更新还款报表
        RepaymentDataModel updateRepay = new RepaymentDataModel();
        updateRepay.setId(currRepay.getId());
        updateRepay.setWhere_version(currRepay.getVersion());
        updateRepay.setRepayment(ArithUtil.sub(ArithUtil.add(repayment_price, overdue_price), currRepay.getDiscount_amount()));
        updateRepay.setOverdue_price(overdue_price);
        updateRepay.setRepayment_status(RepaymentStatusEnum.YES.getCode()); // 是否已还（0：否，1是）
        updateRepay.setRepayment_time(currTime);
        updateRepay.setLast_update_time(currTime);
        int count = repaymentDataDao.updateModel(updateRepay, true);
        if (count != 1) {
            FrameUtil.throwBaseException1("系统繁忙，请稍后重试。");
        }

        // 更新主订单信息
        Map<Object, Object> updateData = FrameUtil.newHashMap();
        updateData.put("interest_pay", repayment_price);
        updateData.put("fine_price", overdue_price);
        updateData.put("limit_pay", currLimit);
        updateData.put("last_update_time", currTime);

        // 如果是最后一期，更新订单为已完成
        if (currLimit == orderModel.getPeriod().intValue()) {
            updateData.put("status", StagesStatusEnum.REPAYMENED.getCode());
        }
        if (orderService.updateByMap(orderModel.getOrder_id(), orderModel.getVersion(), updateData) != 1) {
            FrameUtil.throwBaseException1("系统繁忙，请稍后重试。");
        }

        //普通订单需要返还用户信用额度
        if (OrgMoldEnum.ORDINARY.getCode() == orderModel.getOrder_type()) {
            // 每次还款，返回用户相应的信用额度
            UserDataModel userData = userDataService.getModelById(orderModel.getUser_id(), DbWREnums.READ);
            UserDataModel updateUserData = new UserDataModel();
            updateUserData.setUser_id(userData.getUser_id());
            updateUserData.setWhere_version(userData.getVersion());
            Double incCreditLine = ArithUtil.div(orderModel.getLoan_amount(), orderModel.getPeriod(), 2); //借款使用的额度/贷款期数，精确到小数点后2位
            Double residualAmount = ArithUtil.add(userData.getResidual_amount(), incCreditLine);
            if (residualAmount > userData.getCredit_line()) {
                residualAmount = userData.getCredit_line();
            }
            updateUserData.setResidual_amount(residualAmount);
            if (userDataService.update(updateUserData) != 1) {
                FrameUtil.throwBaseException1("系统繁忙，稍后重试。");
            }
            //记录用户信用额度使用明细
            CreditLineDataModel creditLineDataModel = new CreditLineDataModel();
            creditLineDataModel.setUser_id(orderModel.getUser_id());
            creditLineDataModel.setCost(incCreditLine);
            creditLineDataModel.setType(RecordIncr.addAm.getCode());
            creditLineDataModel.setResidual_amount(residualAmount);
            creditLineDataModel.setRef_id(orderModel.getOrder_id());
            creditLineDataModel.setRef_type(CreditDataRefTableEnum.mfq_order.getValue());
            creditLineDataModel.setCreate_time(currTime);
            creditLineDataService.insert(creditLineDataModel);
        } else if (OrgMoldEnum.VIP.getCode() == orderModel.getOrder_type()) {
            //vip订单 更新商户资金待还金额、已还金额、平台手续费
            OrganizationModel organizationModel = organizationService.getModelById(orderModel.getOrg_id(), DbWREnums.WRITE);
            if (organizationModel == null) {
                FrameUtil.throwBaseException1("订单所属机构不存在");
            }

            Double pf_manage = 0d; //平台分成利息利润
            Double pf_manage_overdue = 0d;//平台分成罚息利润

            if (organizationModel.getInterest_rate() != null && organizationModel.getInterest_rate() > 0) {
                pf_manage = ArithUtil.div(ArithUtil.mul(interest, organizationModel.getInterest_rate()), 100, 2);
            }

            if (organizationModel.getOverdue_rate() != null && organizationModel.getOverdue_rate() > 0) {
                if (overdue_price != null && overdue_price > 0) {
                    pf_manage_overdue = ArithUtil.div(ArithUtil.mul(overdue_price, organizationModel.getOverdue_rate()), 100, 2);
                }
            }

            Integer currDate = Integer.parseInt(DateUtil.timestampToDateString1(currTime,DateUtil.PATTERN_yyyyMMdd));
            //新增一条还款清算记录
            repaymentClearService.insert(new RepaymentClearModel(
                    orderModel.getOrg_id(), orderModel.getOrder_id(), orderModel.getUser_id(),
                    currRepay.getId(), repayment_price, overdue_price, currDate,
                    pf_manage, pf_manage_overdue,interest,currTime));
        }
        // 还款成功提醒
        JpushUtil.pushMessage(orderModel.getUser_id(), Constant.SysParamKeyEnum.PUSH_TPL_REPAYMENT_SUCCESS, orderModel.getOrder_no());

        return count;
    }

    @Override
    public Double calcManagePrice(Long order_id, Integer period) throws Exception {
        Double manager_price = 0D;

        // 逾期管理费开关控制 0 关闭 1 打开，在没有配置时默认为关闭状态
        SysParamModel sysParam = SysParamUtil.getSysParamModel(Constant.SysParamKeyEnum.OVERDUE_MANAGER_FEE_SWITCH);
        String repayment_switch = null == sysParam ? "0" : sysParam.getParam_value();
        if ("0".equals(repayment_switch)) {
            return manager_price;
        }

        OrderModel orderModel = orderService.getModelById(order_id, DbWREnums.READ);
        int loan_day = DateUtil.getInterval(new Date(orderModel.getConfirm_time() * 1000), new Date());
        manager_price = ArithUtil.mul(ArithUtil.div(orderModel.getInterest_price(), 365), loan_day);

        return manager_price;
    }


    @Override
    public List<RepaymentDataModel> reminderRepaymentOrder(Map<String, Object> param) throws Exception {
        param.put("dbtype", this.getBaseDao().getDbtype());
        List<RepaymentDataModel> models = new ArrayList<RepaymentDataModel>();
        PagerModel orders = this.getPageModel(param, "reminderRepaymentOrder", this.getBaseDao(), DbWREnums.READ);
        for (Object obj : orders.getDataList()) {
            models.add((RepaymentDataModel) obj);
        }

        return models;
    }

    /**
     * 还款减免
     *
     * @param repayment_id
     * @param price
     * @throws Exception
     */
    @Override
    public void discount(Long repayment_id, Double price) throws Exception {
        RepaymentDataModel repaymentDataModel = repaymentDataDao.getModelById(repayment_id, true);
        if (repaymentDataModel == null) {
            FrameUtil.throwBaseException1("还款报表记录不存在");
        }

        if (RepaymentStatusEnum.YES.getCode() == repaymentDataModel.getRepayment_status()) {
            FrameUtil.throwBaseException1("该还款报表已还");
        }

        if (price >= repaymentDataModel.getRepayment_amount()) {
            FrameUtil.throwBaseException1("减免金额不能大于当前应还金额");
        }
        Long currTime = FrameUtil.getTime(null);

        // 更新还款报表
        RepaymentDataModel updateRepay = new RepaymentDataModel();
        updateRepay.setId(repaymentDataModel.getId());
        updateRepay.setWhere_version(repaymentDataModel.getVersion());
        updateRepay.setDiscount_amount(price);
        updateRepay.setLast_update_time(currTime);
        int count = repaymentDataDao.updateModel(updateRepay, true);
        if (count != 1) {
            FrameUtil.throwBaseException1("系统繁忙，请稍后重试。");
        }

    }

    @Override
    public PagerModel getRepaymentList(Map map, DbWREnums dbwr) throws Exception {
        return this.getPageModel(map, "getRepaymentList", this.getBaseDao(), dbwr);
    }

    @Override
    public Double querySumPepaymentPrice(Long startTime, Long endTime) throws Exception {
        if(startTime==null||endTime==null){
            FrameUtil.throwBaseException1("请求参数不能为空");
        }
        return repaymentDataDao.querySumPepaymentPrice(FrameUtil.newHashMap("startTime",startTime,"endTime",endTime));
    }

    @Override
    public int repayment(Long repayment_id, Double price, Integer period) throws Exception {
        RepaymentDataModel currRepay = repaymentDataDao.getModelById(repayment_id, true);
        if (null == currRepay) {
            FrameUtil.throwBaseException1("还款报表不存在");
        }

        if (RepaymentStatusEnum.YES.getCode() == currRepay.getRepayment_status()) {
            FrameUtil.throwBaseException1("该还款报表已还");
        }

        int currLimit = currRepay.getPeriod().intValue();
        if (currLimit > 1) {
            //判断上一期是否已经还款
            RepaymentDataModel preRepay = repaymentDataDao.getModelOne(FrameUtil.newHashMap("order_id", currRepay.getOrder_id(), "period", currRepay.getPeriod() - 1), true);
            if (null == preRepay) {
                FrameUtil.throwBaseException1("还款报表异常");
            }

            if (RepaymentStatusEnum.NO.getCode() == preRepay.getRepayment_status()) {
                FrameUtil.throwBaseException1("请先还上一期！");
            }
        }

        OrderModel orderModel = orderService.getModelById(currRepay.getOrder_id(), DbWREnums.READ);
        if (orderModel == null) {
            FrameUtil.throwBaseException1("当前还款的订单不存在");
        }

        if (StagesStatusEnum.REPAYMENTING.getCode() != orderModel.getStatus().intValue()) {
            FrameUtil.throwBaseException1("当前订单状态不合法！");
        }

        if (orderModel.getLimit_pay().intValue() != currRepay.getPeriod().intValue() - 1) {
            FrameUtil.throwBaseException1("当前还款报表异常！");
        }

       FundLoanApplyModel loanApplyModel = fundLoanApplyService.getModelOne(FrameUtil.newHashMap("fund_channel", FundChannelEnum.QIAN_KANG.getValue(),
               "bus_type", BusTypeEnum.LOAN_APPLY.getCode(),"order_id",orderModel.getOrder_id()), DbWREnums.READ);
        if(loanApplyModel==null){
            FrameUtil.throwBaseException1("当前贷款未申请贷款记录");
        }
        RepaymentModeEnum repaymentModeEnum = RepaymentModeEnum.NORMAL;
       if(currRepay.getEstimation_repayment_time()<FrameUtil.getTime()){
           repaymentModeEnum = RepaymentModeEnum.OVERDUE;
       }
        UserDataModel userDataModel = userDataService.getModelOne(FrameUtil.newHashMap("user_id",orderModel.getUser_id()),DbWREnums.WRITE);
        QkRepaymentAskResponse askResponse = QianKangServer.QKRepaymentAsk(orderModel.getOrder_no(),loanApplyModel.getTrade_no(),period,price,repaymentModeEnum.getCode(),userDataModel.getId_name(),userDataModel.getId_number());
        if(askResponse==null){
            FrameUtil.throwBaseException1("还款失败，请重试！");
        }

        if(askResponse.getStatus()==1){
            //还款申请已提交，更新还款报表的状态,
          return  repaymentDataDao.updateByMap(FrameUtil.newHashMap("fund_pay_status",1,"id",currRepay.getId(),"last_update_time",FrameUtil.getTime()),true);
        }
        return 0;
    }


    @Override
    public void repaymentCallBack(QKRepaymentCallBackDto dto) throws Exception {
        if(dto==null){
            FrameUtil.throwBaseException1("请求参数异常");
        }
        FundLoanApplyModel loanApplyModel = fundLoanApplyService.getModelOne(FrameUtil.newHashMap("fund_channel", FundChannelEnum.QIAN_KANG.getValue(),
                "bus_type", BusTypeEnum.LOAN_APPLY.getCode(),"order_id",dto.getOrder_id()), DbWREnums.READ);
        if(loanApplyModel==null){
            FrameUtil.throwBaseException1("请求的订单记录不存在");
        }
        //修改订单更新订单数据
        OrderModel orderModel = orderService.getModelById(loanApplyModel.getOrder_id(), DbWREnums.READ);
        if (orderModel == null) {
            FrameUtil.throwBaseException1("当前还款的订单不存在");
        }
        RepaymentDataModel repaymentDataModel = repaymentDataDao.getModelOne(FrameUtil.newHashMap("order_id",orderModel.getOrder_id(),"period",dto.getTerm_no()),true);
        if(repaymentDataModel==null){
            FrameUtil.throwBaseException1("请求还款报表不存在");
        }
        if(repaymentDataModel.getRepayment_status().intValue()==1){
            //如果还款已经处理则直接返回
            return;
        }

        Long repaymentTime = DateUtil.dateStringToTimestamp(dto.getActual_time(),DateUtil.PATTERN_yyyyMMddHHmmss);
        if(dto.getRepayment_status()==1){
            //修改还款报表信息
            int i = repaymentDataDao.updateByMap(FrameUtil.newHashMap("id",repaymentDataModel.getId(),"where_version",repaymentDataModel.getVersion(),
                    "repayment_status",1,"fund_pay_status",2,"repayment",dto.getActual_amount(),"repayment_time", repaymentTime),true);
            if(i!=1){
                FrameUtil.throwBaseException1("更新还款报表失败，请稍后重试。");
            }

            // 更新主订单信息
            Map<Object, Object> updateData = FrameUtil.newHashMap();
            updateData.put("interest_pay",dto.getActual_amount());
            updateData.put("limit_pay", dto.getTerm_no());
            updateData.put("last_update_time", repaymentTime);

            // 如果是最后一期，更新订单为已完成
            if ( dto.getTerm_no() == orderModel.getPeriod().intValue()) {
                updateData.put("status", StagesStatusEnum.REPAYMENED.getCode());
            }
            if (orderService.updateByMap(orderModel.getOrder_id(), orderModel.getVersion(), updateData) != 1) {
                FrameUtil.throwBaseException1("系统繁忙，请稍后重试。");
            }
            JpushUtil.pushMessage(orderModel.getUser_id(), Constant.SysParamKeyEnum.PUSH_TPL_REPAYMENT_SUCCESS, orderModel.getOrder_no());

        }else {
            //还款失败
           int i = repaymentDataDao.updateByMap(FrameUtil.newHashMap("id",repaymentDataModel.getId(),"where_version",repaymentDataModel.getVersion()
                    ,"fund_pay_status",3,"last_update_time",DateUtil.dateStringToTimestamp(dto.getActual_time(),DateUtil.PATTERN_yyyyMMddHHmmss)),true);
            if(i!=1){
                FrameUtil.throwBaseException1("更新还款报表失败，请稍后重试。");
            }
        }

    }

    @Override
    public List<RepaymentDataModel> updatePlanByOrder(OrderModel order, int period) throws Exception {
        /**
         * 更新还款报表条件：
         * 走资金渠道 && 没有还款完成
         */
        if(     order != null
                && order.getFund_channel().intValue() > 1
                && needUpdateRepaymentPlan(order.getStatus())){
            List<RepaymentDataModel> rdms = this.fundLoanApplyService.createOrUpdateRepaymentPlan(order, period);
            if(period > 0){
                List<RepaymentDataModel> resultList = new ArrayList<>();
                resultList.add(rdms.get(period - 1));
                return resultList;
            }
            return rdms;
        }

        return Collections.EMPTY_LIST;
    }

    private boolean needUpdateRepaymentPlan(int status){
        StagesStatusEnum sse = StagesStatusEnum.parse(status);
        switch (sse){
            case MERCHANT_CONFIRM_CANCEL:
            case REPAYMENTING: return true; // 以上状态需要更新最新还款报表

            case APPLY_SUCCESS:
            case MERCHANT_HANDING:
            case REPAYMENED:
            case LOAN_APPLY:
            case MERCHANT_REFUSAL:
            case MYSEFL_CANCEL:
            case MERCHANT_CANCEL:
            case INVALID:
            case FUND_REFUSE:
            default: return false; // 以上状态不需要更新还款报表
        }
    }



    @Override
    public List<RepaymentDataModel> updatePlanByRepaymentId(Long repaymentId) throws Exception {
        RepaymentDataModel currRepay = repaymentDataDao.getModelById(repaymentId, true);
        if (null == currRepay) {
            FrameUtil.throwBaseException1("还款报表不存在");
        }

        OrderModel orderModel = orderService.getModelById(currRepay.getOrder_id(), DbWREnums.READ);
        if (orderModel == null) {
            FrameUtil.throwBaseException1("当前还款的订单不存在");
        }

        return this.updatePlanByOrder(orderModel, currRepay.getPeriod());
    }

    @Override
    @MnsMsg
    public void sendRepaymentByFundChannelMsg(RepaymentOrderInfoDto repaymentOrderInfoDto) throws Exception {
        MnsUtils.createMessage(repaymentOrderInfoDto.getOrder_id().toString(), MsgTypeEnum.ORDER_REPAYMENT_STATUS_UPDATE,
                MsgOrderServiceEnum.PUBLIC_ORDER_SERVICE, repaymentOrderInfoDto);
    }

    @Override
    public List<RepaymentOrderInfoDto> getUpdateRepaymentOrderInfoList(Map param) throws Exception {
        return repaymentDataDao.getUpdateRepaymentOrderInfoList(param);
    }

    @MnsDispose
    @Override
    public void updateRepaymentOrderInfo(MnsMsgInfo mnsMsgInfo) throws Exception {
        logger.info("贷款消息："+ JSON.toJSONString(mnsMsgInfo));
        RepaymentOrderInfoDto orderInfoDto = StringUtil.getObject(mnsMsgInfo.getBody(), RepaymentOrderInfoDto.class);
        if(orderInfoDto!=null){
           OrderModel orderModel = orderService.getModelById(orderInfoDto.getOrder_id(),DbWREnums.WRITE);
            if(orderModel!=null){
                if(orderModel.getStatus().intValue()==StagesStatusEnum.REPAYMENTING.getCode()){
                    updatePlanByOrder(orderModel,orderModel.getLimit_pay()+1);
                }
            }
        }

    }

    @Resource
    private IRepaymentDataDao repaymentDataDao;

    @Resource
    private IFundsService fundsService;

    @Resource
    private IOrganizationService organizationService;

    @Resource
    private IRepaymentClearService repaymentClearService;

    @Resource
    private IFundLoanApplyService fundLoanApplyService;

    @Override
    public IBaseDao getBaseDao() {
        return this.repaymentDataDao;
    }

}
